﻿/**
*DialogLoadView class
*auth:lww
*version:1.0
*date:2014-10-11
*/
function DialogLoadView(context) {
    this.id = "";
    this.name = "DialogLoadView";
    this.version = "1.0.0";
    this.mContext = context;
    this.mLayoutParams = null;
    this.mViewObject = null;
    this.contentViewObject = null;
    this.isRoundCorner = false;  
    /**
    *info
    */
    this.mLoadView = null;      
    this.mInfoView = null;
    this.infoText = "";
    this.animUrl = DefaultLoadAnimUrl;
    this.mWdith = 240;
    this.mHeight = 160;
}

DialogLoadView.prototype.setRoundCorner = function (b) {
    this.isRoundCorner = b;
};

DialogLoadView.prototype.setWidth = function (w) {
    this.mWdith = w;
};

DialogLoadView.prototype.getWidth = function () {
    return this.mWdith;
};

DialogLoadView.prototype.setHeight = function (h) {
    this.mHeight = h;
};

DialogLoadView.prototype.getHeight = function () {
    return this.mHeight;
};

DialogLoadView.prototype.setStyle = function (animurl) {
    this.animUrl = animurl;
};

DialogLoadView.prototype.invalidate = function () {
    if (this.mViewObject == null) {
        this.mViewObject = new LinearLayout(this.mContext);
    }
    if (this.mLayoutParams == null) {
        this.mLayoutParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
    }
    this.mViewObject.setLayoutParams(this.mLayoutParams);
    return this.mViewObject.view();
};

DialogLoadView.prototype.view = function () {
    return this.invalidate();
};

DialogLoadView.prototype.getId = function () {
    if (this.id == null || this.id == "") {
        this.id = id();
    }
    return this.id;
};

DialogLoadView.prototype.setId = function (ids) {
    this.id = ids;
};

DialogLoadView.prototype.createLoadInfo = function () {
    if (this.mLoadView == null) {

        this.mLoadView = new LinearLayout(this.mContext);
        this.mLoadView.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT));       
        this.mLoadView.setGrative("center");
        var anim = formatHtmlIco(this.animUrl, "auto", "auto", "5px", this.infoText);
        this.mLoadView.addChildView(anim);

        this.mInfoView = new LinearLayout(this.mContext);
        this.mInfoView.setLayoutParams(new LayoutParams(MATCH_PARENT, 40));       
        this.mInfoView.setGrative("center");
        this.mInfoView.setInnerHTML(this.infoText);

        if (this.mViewObject == null) {
            this.invalidate();
        }

        if (this.isRoundCorner) {
            this.mViewObject.setClassName("color1");
            for (var i = 1; i < 5; i++) {
                var bt = $c("b", id()); bt.className = "b" + i.toString();
                this.mViewObject.addChildView(bt);
            }
            this.contentViewObject = new LinearLayout(this.mContext);
            this.contentViewObject.setLayoutParams(new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
            this.contentViewObject.setClassName("content");
            this.mViewObject.addChildView(this.contentViewObject.view());
            for (i = 5; i < 9; i++) {
                var bb = $c("b", id()); bb.className = "b" + i.toString();
                this.mViewObject.addChildView(bb);
            }
            this.contentViewObject.addChildView(this.mLoadView.view());
            this.contentViewObject.addChildView(this.mInfoView.view());
        }
        else {
            this.mViewObject.addChildView(this.mLoadView.view());
            this.mViewObject.addChildView(this.mInfoView.view());
        }
    }
    else {
        this.mInfoView.setInnerHTML(this.infoText);
    }
};

DialogLoadView.prototype.setLoadInfo = function (info) {   
    this.infoText = info;
    this.createLoadInfo();
};

DialogLoadView.prototype.onClose = function (refObj, type) {
    //set to your callback:close interface   
};

DialogLoadView.prototype.setBackground = function (drawable) {
    if (this.mViewObject != null
        && drawable != null
        && typeof (drawable) === "object") {
        var oView = this.mViewObject;
        if (this.contentViewObject != null) {
            oView = this.contentViewObject;
        }
        oView.setBackground(drawable);       
    }
};

markscript("DialogLoadView");
//end DialogLoadView.js